﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;

public class DAL_tbl_shipping_form
{
    public DAL_tbl_shipping_form()
    {

    }



    public List<tbl_shipping_form> select(int ID)
    {
        List<tbl_shipping_form> list = new List<tbl_shipping_form>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select ID,Work_Order_Number,Drum_Bag_Number,Actual_Quantity_from_QC_Sicomill,Shipping_Date,PO_Number,Shipping_Method,Shipping_Vessel,IS_ACTIVE,CREATED_BY,CREATED_DATE,UPDATED_BY,UPDATED_DATE from tbl_shipping_form where ID=@ID";
        cmd.Parameters.AddWithValue("@ID", ID);
        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_shipping_form()
            {
                ID = Convert.ToInt32(dr["ID"]),
                Work_Order_Number = dr["Work_Order_Number"].ToString(),
                Drum_Bag_Number = dr["Drum_Bag_Number"].ToString(),
                Actual_Quantity_from_QC_Sicomill = Convert.ToInt32(dr["Actual_Quantity_from_QC_Sicomill"]),
                Shipping_Date = dr["Shipping_Date"].toDateTimeWithoutError(),
                PO_Number = dr["PO_Number"].ToString(),
                Shipping_Method = dr["Shipping_Method"].ToString(),
                Shipping_Vessel = dr["Shipping_Vessel"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public List<tbl_shipping_form> selectAll()
    {
        List<tbl_shipping_form> list = new List<tbl_shipping_form>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select ID,Work_Order_Number,Drum_Bag_Number,Actual_Quantity_from_QC_Sicomill,Shipping_Date,PO_Number,Shipping_Method,Shipping_Vessel,IS_ACTIVE,CREATED_BY,CREATED_DATE,UPDATED_BY,UPDATED_DATE from tbl_shipping_form Order By ID";

        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_shipping_form()
            {
                ID = Convert.ToInt32(dr["ID"]),
                Work_Order_Number = dr["Work_Order_Number"].ToString(),
                Drum_Bag_Number = dr["Drum_Bag_Number"].ToString(),
                Actual_Quantity_from_QC_Sicomill = Convert.ToInt32(dr["Actual_Quantity_from_QC_Sicomill"]),
                Shipping_Date = dr["Shipping_Date"].toDateTimeWithoutError(),
                PO_Number = dr["PO_Number"].ToString(),
                Shipping_Method = dr["Shipping_Method"].ToString(),
                Shipping_Vessel = dr["Shipping_Vessel"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public int insert(String Work_Order_Number, String Drum_Bag_Number, int Actual_Quantity_from_QC_Sicomill, DateTime Shipping_Date, String PO_Number, String Shipping_Method, String Shipping_Vessel, String CREATED_BY, DateTime CREATED_DATE)
    {
        int i = 0;
        string sql = @"Insert into tbl_shipping_form(Work_Order_Number, Drum_Bag_Number, Actual_Quantity_from_QC_Sicomill, Shipping_Date, PO_Number, Shipping_Method, Shipping_Vessel, CREATED_BY, CREATED_DATE)
                        values(@Work_Order_Number, @Drum_Bag_Number, @Actual_Quantity_from_QC_Sicomill, @Shipping_Date, @PO_Number, @Shipping_Method, @Shipping_Vessel, @CREATED_BY, @CREATED_DATE)";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@Work_Order_Number", Work_Order_Number);
        cmd.Parameters.AddWithValue("@Drum_Bag_Number", Drum_Bag_Number);
        cmd.Parameters.AddWithValue("@Actual_Quantity_from_QC_Sicomill", Actual_Quantity_from_QC_Sicomill);
        cmd.Parameters.AddWithValue("@Shipping_Date", Shipping_Date);
        cmd.Parameters.AddWithValue("@PO_Number", PO_Number);
        cmd.Parameters.AddWithValue("@Shipping_Method", Shipping_Method);
        cmd.Parameters.AddWithValue("@Shipping_Vessel", Shipping_Vessel);
        cmd.Parameters.AddWithValue("@CREATED_BY", CREATED_BY);
        cmd.Parameters.AddWithValue("@CREATED_DATE", CREATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int update(int ID, String Work_Order_Number, String Drum_Bag_Number, int Actual_Quantity_from_QC_Sicomill, DateTime Shipping_Date, String PO_Number, String Shipping_Method, String Shipping_Vessel, String UPDATED_BY, DateTime UPDATED_DATE)
    {
        int i = 0;
        string sql = @"Update tbl_shipping_form SET Work_Order_Number=@Work_Order_Number, Drum_Bag_Number=@Drum_Bag_Number, Actual_Quantity_from_QC_Sicomill=@Actual_Quantity_from_QC_Sicomill, Shipping_Date=@Shipping_Date, PO_Number=@PO_Number, Shipping_Method=@Shipping_Method, Shipping_Vessel=@Shipping_Vessel, UPDATED_BY=@UPDATED_BY, UPDATED_DATE=@UPDATED_DATE WHERE ID=@ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@ID", ID);
        cmd.Parameters.AddWithValue("@Work_Order_Number", Work_Order_Number);
        cmd.Parameters.AddWithValue("@Drum_Bag_Number", Drum_Bag_Number);
        cmd.Parameters.AddWithValue("@Actual_Quantity_from_QC_Sicomill", Actual_Quantity_from_QC_Sicomill);
        cmd.Parameters.AddWithValue("@Shipping_Date", Shipping_Date);
        cmd.Parameters.AddWithValue("@PO_Number", PO_Number);
        cmd.Parameters.AddWithValue("@Shipping_Method", Shipping_Method);
        cmd.Parameters.AddWithValue("@Shipping_Vessel", Shipping_Vessel);
        cmd.Parameters.AddWithValue("@UPDATED_BY", UPDATED_BY);
        cmd.Parameters.AddWithValue("@UPDATED_DATE", UPDATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int delete(int ID)
    {
        int i = 0;
        string sql = "Delete FROM tbl_shipping_form WHERE ID=@ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@ID", ID);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



}